package com.shop.cereshop.commons.tencent.im.model.msg.dto;

import com.shop.cereshop.commons.tencent.im.utils.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 红包消息对象
 * @author zdd
 * @date 2025/9/3 14:32
 * @version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RedPacketMsgDTO {

    /** 红包 ID */
    private String packetId;

    /** 发送者IM账号 */
    private String senderId;

    /** 发送者名称 */
    private String senderName;

    /** 群组 ID */
    private String groupId;

    /** 接收者ID */
    private String receiverId;

    /** 红包祝福语 */
    private String blessing;

    /** 红包封面 */
    private String cover;

    /** 红包总金额 (单位：元) */
    private BigDecimal totalAmount;

    /** 红包数量 */
    private Integer totalCount;

    /** 红包类型：1-普通红包 2-拼手气红包 3-专属红包 */
    private Integer packetType;

    /** 接收者IM账号列表（专属红包时使用） */
    private List<String> targetUserIdList;

    /**
     * 构建红包自定义消息数据
     * @return 自定义消息数据
     */
    public String covertToMsgData() {
        Map<String, Object> data = new HashMap<>();
        data.put("type", "red_packet");
        data.put("version", "1.0");
        data.put("packetId", this.getPacketId());
        data.put("senderId", this.getSenderId());
        data.put("senderName", this.getSenderName());
        data.put("blessing", this.getBlessing());
        data.put("totalAmount", this.getTotalAmount().toString());
        data.put("totalCount", this.getTotalCount());
        data.put("packetType", this.getPacketType());
        data.put("timestamp", System.currentTimeMillis());
        return JsonUtils.toJson(data);
    }

}
